<?php
require_once dirname(__FILE__) . '/libraries/ServiceBase.php';
/**
 * Deposit Service （充值）
 *
 */
class SDOServiceDeposit extends ServiceBase
{
    # 正式环境Deposit WSDL URL
    const DEPOSIT_WSDL = 'DEPOSIT_WSDL';
    # 测试环境Deposit WSDL URL
    const PRE_DEPOSIT_WSDL = 'PRE_DEPOSIT_WSDL';
    # SKEY
    const SKEY = 's*&d!#o.@c)@#o!*m';
    /**
     * 充值接口
     *
     * @param string $message
     * @param string $ptid
     * @param int $depValue
     * @param string $env
     * @return boolean
     */
    public static function NewDepositCard (&$message, $ptid, $depValue, $env = 'pre')
    {
        $wsdl = $env === SDK_ENV_TEST ? sdk_fetch_config(SDK_ENV . self::PRE_DEPOSIT_WSDL) : sdk_fetch_config(SDK_ENV . self::DEPOSIT_WSDL);
        $params['userIdType'] = 1;
        $params['userId'] = 0;
        $params['unlocktime'] = date('Y-m-d H:i:s', strtotime('+ 1 hour'));
        $params['servId'] = 0;
        $params['sdId'] = 0;
        $params['retailPrice'] = 0;
        $params['reserveInt'] = 1;
        $params['ptId'] = $ptid;
        $params['present_info'] = 0;
        $params['periodFlag'] = 1;
        $params['orderId'] = md5(microtime(true). $ptid . self::SKEY);
        $params['inReduceCreditCode'] = 1;
        $params['inReduceCredit'] = 1;
        $params['inRateCode'] = 1;
        $params['inRate'] = 1.0;
        $params['icpId'] = 8;
        $params['hostId'] = 1;
        $params['groupId'] = 0;
        $params['depValue'] = $depValue;
        $params['depTime'] = date('Y-m-d H:i:s');
        $params['depSrcType'] = 99;
        $params['depSrcId'] = 0;
        $params['depSiteType'] = 1;
        $params['depFrom'] = 0;
        $params['depDesType'] = 2;
        $params['dealerprice'] = 0;
        $params['creditId'] = 0;
        $params['createtime'] = date('Y-m-d H:i:s');
        $params['channelId'] = 0;
        $params['cardNum'] = substr($params['orderId'], 0, 20);
        $params['areaId'] = 0;
        $options['soap_version'] = SOAP_1_1;
        if (isset($wsdl['options']) && $wsdl['options']) {
            $options = array_merge($options, $wsdl['options']);
        }
        $result = self::soapRequest('newDepositCard', $params, $wsdl['wsdl'], $options, $message);
        $errMsg = array(SDK_LOG_METHOD=> __FUNCTION__ , SDK_LOG_PARAMS=> json_encode($params) , SDK_LOG_ENV=>$env);
        if ($result===false) {
            $errMsg[SDK_LOG_EXCEPTION] = $message;
            $errMsg[SDK_LOG_LOCATION] = $wsdl['wsdl'];
            self::fatal($errMsg, __CLASS__);
        	return false;
        }
        $errMsg[SDK_LOG_REUTRN] = json_encode($result);
        if ($result->errorcode !== 0) {
            self::warn($errMsg, __CLASS__);
            $message = $result->errorstr;
            self::setErrNo($result->errorcode);
            return FALSE;
        }
        self::log($errMsg, __CLASS__, true);
        return TRUE;
    }
	/**
     * 自检函数
     */
    public static function selfTest() 
    {
    	$arr = array(
        	sdk_fetch_config(SDK_ENV . self::DEPOSIT_WSDL),
        	sdk_fetch_config(SDK_ENV . self::PRE_DEPOSIT_WSDL)
    	);
    	return self::curlTest($arr);
    }
}
